﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class DIC_DEGREE
    {
        private bool m_Active;
        private string m_DegreeCode;
        private string m_DegreeName;
        private string m_Description;

        public DIC_DEGREE()
        {
            m_DegreeCode = "";
            m_DegreeName = "";
            m_Description = "";
            m_Active = true;
        }

        public DIC_DEGREE(string DegreeCode, string DegreeName, string Description, bool Active)
        {
            m_DegreeCode = DegreeCode;
            m_DegreeName = DegreeName;
            m_Description = Description;
            m_Active = Active;
        }

        public bool Active
        {
            get { return m_Active; }
            set { m_Active = value; }
        }

        public string DegreeCode
        {
            get { return m_DegreeCode; }
            set { m_DegreeCode = value; }
        }

        public string DegreeName
        {
            get { return m_DegreeName; }
            set { m_DegreeName = value; }
        }

        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        public string ProductName
        {
            get { return "Class DIC_DEGREE"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        public void AddCheckedComboEdit(CheckedComboBoxEdit checkedCombo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                var item = new CheckedListBoxItem
                {
                    Description = row["DegreeName"].ToString(),
                    CheckState = CheckState.Unchecked,
                    Value = row["DegreeCode"].ToString()
                };
                checkedCombo.Properties.Items.Add(item);
            }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "DegreeName", "DegreeCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["DegreeCode"] = "All";
            row["DegreeName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "DegreeName", "DegreeCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["DegreeName"]);
            }
        }

        public string Delete()
        {
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {m_DegreeCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Delete", myParams, myValues);
        }

        public string Delete(string DegreeCode)
        {
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string DegreeCode)
        {
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_DEGREE_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string DegreeCode)
        {
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_DEGREE_Delete", myParams, myValues);
        }

        public bool Exist(string DegreeCode)
        {
            bool hasRows = false;
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_DEGREE_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string DegreeCode)
        {
            string str = "";
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_DEGREE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_DegreeCode = Convert.ToString(reader["DegreeCode"]);
                    m_DegreeName = Convert.ToString(reader["DegreeName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string DegreeCode)
        {
            string str = "";
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "DIC_DEGREE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_DegreeCode = Convert.ToString(reader["DegreeCode"]);
                    m_DegreeName = Convert.ToString(reader["DegreeName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string DegreeCode)
        {
            string str = "";
            string[] myParams = {"@DegreeCode"};
            object[] myValues = {DegreeCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "DIC_DEGREE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_DegreeCode = Convert.ToString(reader["DegreeCode"]);
                    m_DegreeName = Convert.ToString(reader["DegreeName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("DIC_DEGREE_GetList");
        }

        public string Insert()
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {m_DegreeCode, m_DegreeName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {m_DegreeCode, m_DegreeName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_DEGREE_Insert", myParams, myValues);
        }

        public string Insert(string DegreeCode, string DegreeName, string Description, bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string DegreeCode, string DegreeName, string Description,
            bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_DEGREE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string DegreeCode, string DegreeName, string Description,
            bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_DEGREE_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("DIC_DEGREE", "DegreeCode", "BC");
        }

        public string Update()
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {m_DegreeCode, m_DegreeName, m_Description, m_Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Update", myParams, myValues);
        }

        public string Update(string DegreeCode, string DegreeName, string Description, bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_DEGREE_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string DegreeCode, string DegreeName, string Description,
            bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_DEGREE_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string DegreeCode, string DegreeName, string Description,
            bool Active)
        {
            string[] myParams = {"@DegreeCode", "@DegreeName", "@Description", "@Active"};
            object[] myValues = {DegreeCode, DegreeName, Description, Active};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_DEGREE_Update", myParams, myValues);
        }
    }
}